﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void LoadData()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("A");
            dt.Columns.Add("B");
            dt.Columns.Add("C");
            dt.Columns.Add("D");
            for (int i = 0; i < 100; i++)
            {
                var row = dt.NewRow();
                row["A"] = "a" + i;
                row["B"] = "b" + i;
                row["C"] = "c" + i;
                row["D"] = "d" + i;
                dt.Rows.Add(row);
                Task.Delay(100).Wait();
            }
            this.dataGridView1.Invoke(new MethodInvoker(() => {
                this.dataGridView1.DataSource = dt;
            }));
        }

        private void Form1_Shown(object sender, EventArgs e)
        {
            Task.Run(() =>
            {
                LoadData();
            });
        }
    }
}
